package cn.appsys.controller.backend;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.appsys.pojo.AppCategory;
import cn.appsys.pojo.DataDictionary;
import cn.appsys.service.AppCategoryService;
import cn.appsys.service.DataDictionaryService;
import cn.appsys.tools.Constants;

@Controller
@RequestMapping("/manager/backend")
public class AppInfoController {
	private Logger log = Logger.getLogger(BackendLoginController.class);
	
	@Resource
	public AppCategoryService appCategoryService; //加载一二三级分类
	
	@Resource
	public DataDictionaryService dataDictionaryService;//加载所属平台
	
	@RequestMapping("/applist")
	public String toAppList(Model model) {
		log.debug("===================toAppList:");
		//加载所有app列表信息
		//分页信息
		
		List<DataDictionary> dictionaryList=null;
		List<AppCategory> categoryLevel1List=null;
		try {
			//加载所属平台
			dictionaryList = dataDictionaryService.getDataDictionaryByCode(Constants.APP_FLATFORM);
			//加载一级分类
			categoryLevel1List= appCategoryService.getCategoryByPid(null);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		log.debug("=====所属平台数量:"+dictionaryList.size());
		log.debug("=====所属一级分类:"+categoryLevel1List.size());
		//数据放入model
		model.addAttribute("flatFormList", dictionaryList);
		model.addAttribute("categoryLevel1List", categoryLevel1List);
		return "backend/applist";
	}


	@RequestMapping("/getAppCategoryList.json")
	@ResponseBody
	public List<AppCategory> getAppCategoryList(@RequestParam("pid") String pid) {
		Integer _pid = pid==null?null:Integer.valueOf(pid);
		return appCategoryService.getCategoryByPid(_pid);
		
	}
}
